﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class dathang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        txtOrderDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DAOOrder dao_Order = new DAOOrder();
        DAO_User dao_User = new DAO_User();
        String account = (String)Session["account"];
        int UserId = dao_User.GetUserIdByAccount(account);
        int OrderId = dao_Order.InsertOrder(UserId, DateTime.Now, txtTenNguoiNhan.Text, txtDiaChiNguoiNhan.Text, txtDienThoaiNguoiNhan.Text);

        DataTable dt = (DataTable)Session["GioHang"];

        foreach (DataRow row in dt.Rows)
        {
           int ProId= (int)row["idSP"];
           int Quantity = (int)row["SoLuong"];
           dao_Order.InsertOrderDetail(OrderId, ProId, Quantity); 
        }
        Session["GioHang"] = null;
        Response.Write("<script>alert('Đặt hàng thảnh công')</script>");
        Response.Redirect("~/index.aspx");
    }
}